﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Configuration;

namespace Electure
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var queryString = Request.QueryString["ReturnUrl"];
            if (queryString.Split(new string[] { "electure" }, StringSplitOptions.None).Length > 1)
                Response.Redirect("~/login?ReturnUrl=" + queryString.Replace("%2felecture", "").Replace("/electure", ""));
        }

        protected void btLogin_Click(object sender, EventArgs e)
        {
            lbError.Visible = false;
            if (ConfigurationManager.AppSettings[tbLogin.Text] == tbPassword.Text)
            {
                FormsAuthentication.SetAuthCookie("admin", false);
                Response.Redirect("~/" + Request.QueryString["ReturnUrl"]);
            }
            else
            {
                lbError.Visible = true;
            }
            //Response.Redirect("~/" + Request.QueryString["ReturnUrl"].Replace("%2felecture", "").Replace("/electure", ""));
        }
    }
}